import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:pornhub_app/components/activity_cell/activity_cell.dart';
import 'package:pornhub_app/components/app_bar/app_bar_view.dart';
import 'package:pornhub_app/components/base_refresh/base_refresh_widget.dart';
import 'package:pornhub_app/components/image_view.dart';
import 'package:pornhub_app/components/no_more/no_data.dart';
import 'package:pornhub_app/components/text_view.dart';
import 'package:pornhub_app/utils/color.dart';
import 'package:pornhub_app/utils/extension.dart';

import '../../../routes/routes.dart';
import '../controllers/activity_page_controller.dart';

class ActivityPage extends GetView<ActivityPageController> {
  const ActivityPage({super.key});

  @override
  Widget build(BuildContext context) {
    PreferredSizeWidget _buildAppBar() => AppBarView(
          titleText: '活动',
          actions: [
            TextView(
              text: "我的活动",
              style: TextStyle(fontSize: 12.w, color: COLOR.white),
            ).onTap(() => Get.toNamed(Routes.activityMy)).baseMarginR,
          ],
        );
    return Scaffold(
      backgroundColor: COLOR.color_111,
      appBar: _buildAppBar(),
      body: BaseRefreshWidget(
        controller,
        child: GetBuilder<ActivityPageController>(builder: (_) {
          return CustomScrollView(
            slivers: [
              if (controller.imgString.value.isNotEmpty)
                SliverToBoxAdapter(
                  child: Container(
                    margin: EdgeInsets.symmetric(horizontal: 14.w),
                    height: 186.w,
                    clipBehavior: Clip.hardEdge,
                    decoration:
                        BoxDecoration(borderRadius: BorderRadius.circular(4.w)),
                    child: ImageView(src: controller.imgString.value),
                  ).marginBottom(20.w),
                ),
              if (controller.isLoadData && controller.activityList.isEmpty)
                const NoData().marginTop(44).sliver,
              SliverPadding(
                padding: EdgeInsets.only(left: 14.w, right: 14.w),
                sliver: SliverList.builder(
                    itemCount: controller.activityList.length,
                    itemBuilder: (context, index) {
                      return ActivityCell(
                          index: index,
                          activity: controller.activityList[index]);
                    }),
              )
            ],
          );
        }),
      ),
    );
  }
}
